//
//  DemoPopOverViewController.m
//  DemoPopOver
//
//  Created by duc nguyen van on 8/11/11.
//  Copyright 2011 STU. All rights reserved.
//

#import "DemoPopOverViewController.h"

@implementation DemoPopOverViewController
@synthesize label;
@synthesize infoTable;
@synthesize popInfoTable;
@synthesize imageTable;
@synthesize popImageTable;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/
#pragma mark delegateInfoTable
-(void)inforTableClick:(NSString *)string{
	label.text = string;
	if(popInfoTable != nil)[popInfoTable dismissPopoverAnimated:YES];
}

#pragma mark -
#pragma mark click event
-(IBAction)Click:(id)sender{
	//UIViewController *newView = [[UIViewController alloc]init];
//	
//	UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:newView];
//	[pop setDelegate:self];
//	[pop presentPopoverFromBarButtonItem:sender 
//				permittedArrowDirections:UIPopoverArrowDirectionAny 
//								animated:YES];
//	[pop setPopoverContentSize:CGSizeMake(320, 400)];
//	[newView release];
	
	if(infoTable == nil)infoTable = [[InfoTable alloc] init];
	infoTable.delegate = self;
	if (popInfoTable == nil) {
		popInfoTable = [[UIPopoverController alloc] initWithContentViewController:infoTable];
		[popInfoTable setDelegate:self];
	}
	[popInfoTable presentPopoverFromBarButtonItem:sender 
						 permittedArrowDirections:UIPopoverArrowDirectionAny 
										 animated:YES];
	[popInfoTable setPopoverContentSize:CGSizeMake(320, 400)];
}

-(IBAction)ClickImage:(id)sender{
	if(imageTable == nil)imageTable = [[ImageTable alloc] init];
	if (popImageTable == nil) {
		popImageTable = [[UIPopoverController alloc] initWithContentViewController:imageTable];
		[popImageTable setDelegate:self];
	}
	[popImageTable presentPopoverFromBarButtonItem:sender 
						 permittedArrowDirections:UIPopoverArrowDirectionAny 
										 animated:YES];
	[popImageTable setPopoverContentSize:CGSizeMake(320, 400)];
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
